package com.koron.css2.netHall;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjInfoBean;
import com.koron.css2.newProjectCenter.impl.PjSave;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.ServicePtUserBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.Arrays;
import java.util.List;

/**
 * com.koron.css2.netHall
 *
 * @author YinJiaLin
 * @since 2025/3/20
 */
public class GetNetHallMessage implements ServerInterface {

    private static final List<String> DEFAULT_WATER_CODES = Arrays.asList("C021903");
    private static final List<String> DEFAULT_AREA_CODES = Arrays.asList(
            "15", "12", "11", "10", "09", "08", "07", "06", "05", "04", "03", "01", "02"
    );
    
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        String data = JsonUtils.objectToJson(req.getData());
        JsonNode jsonNode = JsonUtils.stringToJsonNode(data);
        PjInfoBean pjInfoBean = null;
        if (jsonNode != null) {
            pjInfoBean = JSONObject.parseObject(jsonNode.get("consult").toString(), PjInfoBean.class);
        }
        if (pjInfoBean != null) {
            pjInfoBean.setProcessState(null);
        }
        UserInfoBean userInfoBean = getUserInfoBean();
        PjSave pjSave = new PjSave();
        pjSave.exec(factory,userInfoBean,req);
        return NewHallResult.success("success");
    }

    private static UserInfoBean getUserInfoBean() {
        UserInfoBean userInfoBean = new UserInfoBean();
        userInfoBean.setCurService("002");
        userInfoBean.setCurWaterCode("C021903");
        userInfoBean.setIpAddr("192.168.2.72");
        userInfoBean.setWaterCode(DEFAULT_WATER_CODES);
        ServicePtUserBean user = new ServicePtUserBean();
        user.setAcount("designer");
        user.setName("系统设计师");
        user.setCode("designer");
        userInfoBean.setUserInfo(user);
        return userInfoBean;
    }
}
